package com.example.mydy.model;

import android.content.Context;
import com.google.gson.annotations.SerializedName;

/**
 * 任务模型类
 */
public class Task {
    @SerializedName("id")
    private int id;
    
    @SerializedName("title")
    private String title;
    
    @SerializedName("description")
    private String description;
    
    @SerializedName("reward")
    private double reward;
    
    @SerializedName("status")
    private String status;
    
    @SerializedName("username")
    private String username;
    
    @SerializedName("imageUrl")
    private String imageUrl;
    
    @SerializedName("submittedAt")
    private String submittedAt;
    
    @SerializedName("link")
    private String link;
    
    @SerializedName("content")
    private String content;
    
    @SerializedName("reviewTime")
    private String reviewTime;
    
    @SerializedName("rejectReason")
    private String rejectReason;
    
    // 状态常量
    public static final String STATUS_AVAILABLE = "available";
    public static final String STATUS_IN_PROGRESS = "in_progress";
    public static final String STATUS_COMPLETED = "completed";
    public static final String STATUS_VERIFIED = "verified";
    public static final String STATUS_FAILED = "failed";
    
    // 新状态常量
    public static final String STATUS_PENDING = "pending";
    public static final String STATUS_APPROVED = "approved";
    public static final String STATUS_REJECTED = "rejected";
    
    // 非序列化字段，不会发送到服务器
    private transient Context context;
    
    public Task() {
        // 默认构造函数
    }
    
    // Getter和Setter方法
    public int getId() {
        return id;
    }
    
    public void setId(int id) {
        this.id = id;
    }
    
    public String getTitle() {
        return title;
    }
    
    public void setTitle(String title) {
        this.title = title;
    }
    
    public String getDescription() {
        return description;
    }
    
    public void setDescription(String description) {
        this.description = description;
    }
    
    public double getReward() {
        return reward;
    }
    
    public void setReward(double reward) {
        this.reward = reward;
    }
    
    public String getStatus() {
        return status;
    }
    
    public void setStatus(String status) {
        this.status = status;
    }
    
    public String getUsername() {
        return username;
    }
    
    public void setUsername(String username) {
        this.username = username;
    }
    
    public String getImageUrl() {
        return imageUrl;
    }
    
    public void setImageUrl(String imageUrl) {
        this.imageUrl = imageUrl;
    }
    
    public String getSubmittedAt() {
        return submittedAt;
    }
    
    public void setSubmittedAt(String submittedAt) {
        this.submittedAt = submittedAt;
    }
    
    public String getLink() {
        return link;
    }
    
    public void setLink(String link) {
        this.link = link;
    }
    
    public String getContent() {
        return content;
    }
    
    public void setContent(String content) {
        this.content = content;
    }
    
    public String getReviewTime() {
        return reviewTime;
    }
    
    public void setReviewTime(String reviewTime) {
        this.reviewTime = reviewTime;
    }
    
    public String getRejectReason() {
        return rejectReason != null ? rejectReason : "";
    }
    
    public void setRejectReason(String reason) {
        this.rejectReason = reason;
    }
    
    // 额外添加的兼容方法
    public String getCreatedAt() {
        return submittedAt;
    }
    
    public void setCreatedAt(String createdAt) {
        this.submittedAt = createdAt;
    }
    
    public int getUserId() {
        return -1; // 默认返回-1
    }
    
    public void setUserId(int userId) {
        // 空实现，保持兼容性
    }
    
    public void setRejectionReason(String reason) {
        // 空实现，保持兼容性
    }
    
    // 辅助方法，检查任务是否可以接受
    public boolean isAvailable() {
        return STATUS_AVAILABLE.equals(status);
    }
    
    // 辅助方法，检查任务是否已完成
    public boolean isCompleted() {
        return STATUS_COMPLETED.equals(status) || STATUS_VERIFIED.equals(status);
    }
    
    // 辅助方法，检查任务是否待审核
    public boolean isPending() {
        return STATUS_PENDING.equals(status);
    }
    
    // 辅助方法，检查任务是否已批准
    public boolean isApproved() {
        return STATUS_APPROVED.equals(status);
    }
    
    // 辅助方法，检查任务是否已拒绝
    public boolean isRejected() {
        return STATUS_REJECTED.equals(status);
    }
    
    public Context getContext() {
        return context;
    }
    
    public void setContext(Context context) {
        this.context = context;
    }

    @Override
    public String toString() {
        return "Task{" +
                "id=" + id +
                ", title='" + title + '\'' +
                ", description='" + description + '\'' +
                ", reward=" + reward +
                ", status='" + status + '\'' +
                ", username='" + username + '\'' +
                '}';
    }
}